<%
local dsp = require "luci.dispatcher"
local ipkg = require "luci.model.ipkg"
-%>

<% include("cbi/map") %>
<script type="text/javascript">//<![CDATA[
	var ssr_python_status = document.getElementsByClassName('ssr_python_status')[0];
	ssr_python_status.setAttribute("style","font-weight:bold;");
	<% if ipkg.installed("python") then %>
		XHR.poll(2, '<%=luci.dispatcher.build_url("admin", "vpn", "ssr_python_pro_server", "status")%>', null,
			function(x, result)
			{
				ssr_python_status.setAttribute("color",result.status ? "green":"red");
				ssr_python_status.innerHTML = result.status?'<%=translate("RUNNING")%>':'<%=translate("NOT RUNNING")%>';
			}
		)
	<% else %>
		ssr_python_status.setAttribute("color","red");
		ssr_python_status.innerHTML = '<%=translate("NOT INSTALLED")%><br><%=translate("please Install the python")%><br>opkg update && opkg install python</font></b>';
	<% end %>
	
	function ssr_python_get_total_traffic(section,dom) {
		XHR.get('<%=luci.dispatcher.build_url("admin", "vpn", "ssr_python_pro_server", "get_total_traffic")%>', { "section" : section },
			function(x, result)
			{
				if(x && x.status == 200)
					dom.outerHTML = result.result;
			}
		)
	}
	
	function ssr_python_get_link(section) {
		XHR.get('<%=luci.dispatcher.build_url("admin", "vpn", "ssr_python_pro_server", "get_link")%>', { "section" : section },
			function(x, result)
			{
				if(x && x.status == 200)
					alert(result.link);
			}
		)
	}
	
	/* var ssr_python_users_status = document.getElementsByClassName('ssr_python_users_status');
	for(var i = 0; i < ssr_python_users_status.length; i++) {
		var id_div = ssr_python_users_status[i].parentElement.parentElement.parentElement.id;
		var port_div = document.getElementById(id_div+"-port");
		var port = port_div.outerText;
		XHR.poll(1,'<%=dsp.build_url("admin/vpn/ssr_python_pro_server/users_status")%>', {
				index: i,
				port: port
			},
			function(x, result) {
				ssr_python_users_status[result.index].innerHTML = (result.status ? '<b><font color="green">✓</font></b>' : '<b><font color="red">X</font></b>');
			}
		);
	} */
//]]>
</script>
